package com.trkj.dao.jpa;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.trkj.pojos.YzrPurchOrder;

public interface IYzrPurchOrderDAO extends CrudRepository<YzrPurchOrder, String> {
    
	//找出最大编号
	@Query("select max(po.purchOrderId) from YzrPurchOrder po where po.purchOrderId like ?1%")
    public String findID(String a);

	// 查找出‘未验收’and‘未入库’的采购订单
	@Query("select po from YzrPurchOrder po where po.purchYanshouState='未验收' and po.purchInstockState='未入库' order by po.purchOrderId desc")
	public List<YzrPurchOrder> findAllOrderByNoCheck(Pageable pageable);
	
	// 查找出‘已验收’and‘未入库’的采购订单
	@Query("select po from YzrPurchOrder po where po.purchYanshouState='已验收' and po.purchInstockState='未入库' order by po.purchOrderId desc")
	public List<YzrPurchOrder> findAllOrderByNoInstock(Pageable pageable);
	//查找所有订单
	@Query("select po from YzrPurchOrder po order by po.purchOrderId desc")
	public List<YzrPurchOrder> findAllOrder(Pageable pageable);
	
	//根据采购人查询 
	@Query("select po from YzrPurchOrder po where po.purchPeople = ?1 order by po.purchOrderId desc")
	public List<YzrPurchOrder> findOrderByPeople(BigDecimal name,Pageable pageable);
	
	//根据验收状态查询 
	@Query("select po from YzrPurchOrder po where po.purchYanshouState like %?1% order by po.purchOrderId desc")
	public List<YzrPurchOrder> findOrderByCheckState(String state,Pageable pageable);
	
	//根据入库状态查询 
	@Query("select po from YzrPurchOrder po where po.purchInstockState like %?1% order by po.purchOrderId desc")
	public List<YzrPurchOrder> findOrderByRuKuState(String state,Pageable pageable);
	
	//根据id查询 
	@Query("select po from YzrPurchOrder po where po.purchOrderId = ?1 order by po.purchOrderId desc")
	public List<YzrPurchOrder> findOrderById(String orderId,Pageable pageable);
	
	//根据交货期日的时间段查询
	@Query("select po from YzrPurchOrder po where po.purchJiaohuoDate between ?1 and ?2 order by po.purchOrderId desc")
	public List<YzrPurchOrder> findOrderByJiaoHuoDate(Date startDate,Date endDate, Pageable pageable);

	
}
